import torch

x = 2.0
y = 4.0
w = torch.Tensor([1.0])
w.requires_grad = True

l = (x * w - y) ** 2
l.backward()
print(l)
print(w.grad)
